<?php

/**
 * Abonnement filter form base class.
 *
 * @package    tfe
 * @subpackage filter
 * @author     3emeIG
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseAbonnementFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'libelle'                              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'saison'                               => new sfWidgetFormChoice(array('choices' => array('' => '', '2007-2008' => '2007-2008', '2008-2009' => '2008-2009', '2009-2010' => '2009-2010', '2010-2011' => '2010-2011', '2012-2013' => '2012-2013', '2014-2015' => '2014-2015', '2015-2016' => '2015-2016', '2016-2017' => '2016-2017', '2018-2019' => '2018-2019', '2019-2020' => '2019-2020'))),
      'code'                                 => new sfWidgetFormFilterInput(),
      'nombre_de_spectacles'                 => new sfWidgetFormFilterInput(),
      'prix_en_prevente'                     => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'prix_en_saison'                       => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'prix_par_semestre'                    => new sfWidgetFormFilterInput(),
      'prix_pour_membres'                    => new sfWidgetFormFilterInput(),
      'commentaire'                          => new sfWidgetFormFilterInput(),
      'deleted_at'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'created_at'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'spectacles_list'                      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Spectacle')),
      'courriers_electroniques_envoyes_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'CourrierElectronique')),
    ));

    $this->setValidators(array(
      'libelle'                              => new sfValidatorPass(array('required' => false)),
      'saison'                               => new sfValidatorChoice(array('required' => false, 'choices' => array('2007-2008' => '2007-2008', '2008-2009' => '2008-2009', '2009-2010' => '2009-2010', '2010-2011' => '2010-2011', '2012-2013' => '2012-2013', '2014-2015' => '2014-2015', '2015-2016' => '2015-2016', '2016-2017' => '2016-2017', '2018-2019' => '2018-2019', '2019-2020' => '2019-2020'))),
      'code'                                 => new sfValidatorPass(array('required' => false)),
      'nombre_de_spectacles'                 => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'prix_en_prevente'                     => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'prix_en_saison'                       => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'prix_par_semestre'                    => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'prix_pour_membres'                    => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'commentaire'                          => new sfValidatorPass(array('required' => false)),
      'deleted_at'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'created_at'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'spectacles_list'                      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Spectacle', 'required' => false)),
      'courriers_electroniques_envoyes_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'CourrierElectronique', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('abonnement_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addSpectaclesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.ListeSpectacles ListeSpectacles')
          ->andWhereIn('ListeSpectacles.id_spectacle', $values);
  }

  public function addCourriersElectroniquesEnvoyesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.AbonnementDestinataire AbonnementDestinataire')
          ->andWhereIn('AbonnementDestinataire.id_courrier_electronique', $values);
  }

  public function getModelName()
  {
    return 'Abonnement';
  }

  public function getFields()
  {
    return array(
      'id'                                   => 'Number',
      'libelle'                              => 'Text',
      'saison'                               => 'Enum',
      'code'                                 => 'Text',
      'nombre_de_spectacles'                 => 'Number',
      'prix_en_prevente'                     => 'Number',
      'prix_en_saison'                       => 'Number',
      'prix_par_semestre'                    => 'Number',
      'prix_pour_membres'                    => 'Number',
      'commentaire'                          => 'Text',
      'deleted_at'                           => 'Date',
      'created_at'                           => 'Date',
      'updated_at'                           => 'Date',
      'spectacles_list'                      => 'ManyKey',
      'courriers_electroniques_envoyes_list' => 'ManyKey',
    );
  }
}
